package com.gitee.wsl.mathematics.matrix.mat

import com.gitee.wsl.io.dataproxy.DataProxy
import com.gitee.wsl.lang.array.SparseArray

class SparseMatrix(rowCount: Int,
                   colCount: Int = rowCount,
                   proxy: DataProxy<Double> = SparseArray<Double>().asProxy(rowCount*colCount,0.0)
): AbstractMatrix<SparseMatrix>(rowCount, colCount, proxy) {
    override val self: SparseMatrix
        get() = this

}

fun <T> SparseArray<T>.asProxy(size: Int,default: T) = SparseArrayProxy(size,this,default)

class SparseArrayProxy<T>(override val size: Int,val base:SparseArray<T>,val default:T ):DataProxy<T>{

    override fun fill(value: T, fromIndex: Int, toIndex: Int) {
        (fromIndex..toIndex).forEach { set(it,value) }
    }

    override fun get(index: Int): T {
        return base[index] ?:default
    }

    override fun values(): List<T> = (0..size).map { get(it) }

    override fun set(index: Int, value: T) {
        base[index] = value
    }

}

